package system_code.CopyFile;

import java.io.*;
import java.util.Scanner;

public class Test3 {
    public static void main(String[] args){
        System.out.print("请输入您要复制的文件名:");
        Scanner scanner = new Scanner(System.in);
        File srcFile = new File(scanner.next());
        if(!srcFile.isFile()){
            System.out.println("该文件名无效!");
            return;
        }
        System.out.print("请输入您要复制到何文件夹下:");
        File rootFile = new File(scanner.next());
        if(!rootFile.isDirectory()){
            System.out.println("该文件夹名无效!");
            return;
        }
        System.out.print("请输入拷贝后的文件名:");
        File copyFile = new File(scanner.next());
        try(InputStream inputStream = new FileInputStream(srcFile);
            OutputStream outputStream = new FileOutputStream(copyFile)){
            while(true) {
                int ret = inputStream.read();
                if(ret == -1){
                    System.out.println("拷贝成功!");
                    return;
                }
                outputStream.write(ret);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
